<?php

namespace app\service;

use app\dao\TeacherDao;
use app\model\TeacherModel;
use think\exception\ValidateException;
use think\facade\Log;

class TeacherService
{

    protected $teacherDao;

    public function __construct()
    {

        $this->teacherDao = new TeacherDao();
    }


    //增加
    public function addTeacher($data)
    {

        try {

            $this->teacherDao->addTeacherDao($data);

        } catch (\Exception $e) {
//            Log::error("增加指导老师失败: " . $e->getMessage());
//            return null;
            throw new ValidateException("教师信息增加失败");
        }


    }

    //教师列表
    public function listTeachers()
    {
        try {

             return $this->teacherDao->listTeachersDao();

        } catch (\Exception $e) {

            throw new ValidateException("教师信息获取失败");
        }
    }

    public function getTeacher($id){

        try {

            return $this->teacherDao->getTeacher($id);

        } catch (\Exception $e) {

            throw new ValidateException("教师信息获取失败");
        }
    }

    //删除

    public function deleteTeacher($id)
    {
        try {

           return $this->teacherDao->deleteTeacherDao($id);

        } catch (\Exception $e) {
//            Log::error("删除指导老师失败: " . $e->getMessage());
//            return null;
            throw new ValidateException("教师信息删除失败");
        }

    }


    //修改
    public function updateTeacher($id, $data)
    {
        try {

           return $this->teacherDao->updateTeacherDao($id, $data);

        } catch (\Exception $e) {
//            Log::error("删除指导老师失败: " . $e->getMessage());
//            return null;
            throw new ValidateException("教师信息修改失败");
        }

    }
}